<ui:composition template="mainTemplate.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                >
    <ui:define name="content">
        <p:messages />
        <h:panelGrid columns="2">
            Filename
            <h:outputText value="#{fileInfoController.fileinfo.name}"/>

            Description
            <h:outputText value="#{fileInfoController.fileinfo.description}"/>

            Date uploaded
            <h:outputText value="#{fileInfoController.fileinfo.datecreated}"/>

            Uploader
            <h:link outcome="pretty:profile">
                <h:outputText value="#{fileInfoController.fileinfo.user.firstname} 
                              #{fileInfoController.fileinfo.user.lastname}"/>
                <f:param name="id" value="#{fileInfoController.fileinfo.user.id}"/>
            </h:link>

            Download link:
            <h:panelGroup rendered="#{userController.loggedIn}">
                <a href="download?id=#{param['id']}">Download now!</a>
            </h:panelGroup>

            <h:panelGroup rendered="#{not userController.loggedIn}">
                <h:link outcome="pretty:login">Log in</h:link> to download files!
            </h:panelGroup>
        </h:panelGrid>


        <h:form rendered="false">
            <br/>
            <h:commandButton action="#{fileInfoController.deleteFile()}" value="Delete"/>
        </h:form>

        <br/>
        <h3>Comments</h3>
        <h:form>
            <h:dataTable value="#{commentController.items}" var="item"
                         bgcolor="#fafafa" border="0" cellpadding="5" cellspacing="3"
                         first="0" width="50%" frame="border" styleClass="dataTable">
                <h:column>
                    <f:facet name="header">
                        Username
                    </f:facet>
                    <h:link outcome="pretty:profile">
                        #{item.user.firstname} #{item.user.lastname}
                        <f:param name="id" value="#{item.user.id}"/>
                    </h:link>
                </h:column>

                <h:column>
                    <f:facet name="header">
                        Message
                    </f:facet>
                    <h:outputText value="#{item.message}"/>
                </h:column>

                <h:column>
                    <f:facet name="header">
                        Timestamp
                    </f:facet>
                    <h:outputText value="#{item.timestamp}"/>
                </h:column>

                <h:column rendered="#{userController.isAdmin}">
                    <f:facet name="header">
                        Administer
                    </f:facet>
                    <h:commandButton action="#{commentController.removeComment(item)}" value="Delete"/>
                </h:column>
            </h:dataTable>
            <br/>
            <h:outputText value="#{commentController.pagination.pageFirstItem + 1}..#{commentController.pagination.pageLastItem + 1}/#{commentController.pagination.itemsCount}"/>
            <br/>
            <h:commandLink action="#{commentController.previous}" value="Previous #{commentController.pagination.pageSize}" rendered="#{commentController.pagination.hasPreviousPage}"/> 
            <h:commandLink action="#{commentController.next}" value="Next #{commentController.pagination.pageSize}" rendered="#{commentController.pagination.hasNextPage}"/>
        </h:form>
        <h:form rendered="#{userController.loggedIn}">
            <h4>Submit comment</h4>
            <h:inputTextarea value="#{commentController.message}"/><br/>
            <h:commandButton action="#{commentController.postMessage()}" value="Post" />
        </h:form>
    </ui:define>
</ui:composition>